package com.digital.welcome.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.digital.welcome.entity.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * @author 韩
 */
@Mapper
@Repository
public interface PermissionMapper extends BaseMapper<Permission> {

    List<Permission> selectAllPermissionByUsername(String username);

    Set<String> selectAllPermissionCodeByUsername(String username);

    List<String> selectAllPermissionNameByUsername(String username);

    List<String> selectAllPermissionNameByRoleId(Integer roleId);

    @Select("select permission_id from permission where permission_name = #{permissionName}")
    Integer getPermissionIdByPermission(String permissionName);

    @Insert("insert into roler_permission values (#{roleId}, #{permissionId})")
    boolean insertRolePermission(int roleId, int permissionId);

    @Delete("delete from roler_permission where role_id = #{roleId} and permission_id = #{permissionId}")
    void deletePermissionByPermissionIdAndRoleId(Integer permissionId, Integer roleId);

}
